package com.lishe.lishe.retrofit.MyObserver;

import java.util.Observable;

import io.reactivex.annotations.NonNull;
import io.reactivex.observers.DefaultObserver;

/**
 * Created by DELL on 2017/11/22.
 */

public abstract class FileUploadObserver<T> extends DefaultObserver<T> {

    @Override
    public void onStart() {
        super.onStart();
        onUpLoadStart();
    }

    @Override
    public void onNext(@NonNull T t) {
        onUpLoadSuccess(t);
    }

    @Override
    public void onError(@NonNull Throwable e) {
        onUpLoadFail(e);
    }

    @Override
    public void onComplete() {

    }

    //监听进度的改变
    public void onProgressChange(long bytesWritten,long contentLength){
        onProgress((int)bytesWritten,(int)contentLength);
    }

    protected abstract void onProgress(int bytesWritten, int contentLength);

    protected abstract void onUpLoadFail(Throwable e);

    protected abstract void onUpLoadSuccess(T t);

    protected abstract void onUpLoadStart();
}
